package com.alex.web.db.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页查询结果对象，兼容SPRING JPA
 *
 * Created by weijs on 2017/11/2.
 */
public class PageControl<T> implements Serializable {

    /**
     * 当前页码，为了兼容JPA
     */
    private int number;

    /**
     * 每页条数
     */
    private int size;

    /**
     * 总记录数
     */
    private long total;


    private List<T> entityList = new ArrayList<T>();


    /**
     * 返回查询结果列表，兼容原来的分页
     * @return
     */
    public List<T> getContent() {
        return this.entityList;
    }

    /**
     * 返回总页数，兼容原来的分页
     * @return
     */
    public int getTotalPages() {
        return this.getSize() == 0?1:(int)Math.ceil((double)this.total / (double)this.getSize());
    }

    /**
     * 返回总记录数，兼容原来的分页
     * @return
     */
    public long getTotalElements() {
        return this.total;
    }


    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getEntityList() {
        return entityList;
    }

    public void setEntityList(List<T> entityList) {
        this.entityList = entityList;
    }
}
